# Maintainer: Naveen M K <naveen521kk@gmail.com>

_realname=bat
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.18.3
pkgrel=1
pkgdesc="Cat clone with syntax highlighting and git integration (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/sharkdp/bat'
license=(APACHE MIT)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
)
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/sharkdp/bat/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('dff7fa5222f40c7b3c783d3ceb0c3ffb35662f1198b00d785f80f3f1523399dd')

prepare() {
  cp -r ${_realname}-${pkgver} build-${MSYSTEM}
  ${MINGW_PREFIX}/bin/cargo fetch \
  --locked \
  --manifest-path build-${MSYSTEM}/Cargo.toml
}

build() {
  ${MINGW_PREFIX}/bin/cargo build \
  --release \
  --manifest-path build-${MSYSTEM}/Cargo.toml
}

package() {
  ${MINGW_PREFIX}/bin/cargo install \
  --offline \
  --no-track \
  --path build-${MSYSTEM} \
  --root ${pkgdir}${MINGW_PREFIX}

  # Package licenses
  install -Dm644 build-${MSYSTEM}/LICENSE-APACHE \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/$pkgname/LICENSE-APACHE
  install -Dm644 build-${MSYSTEM}/LICENSE-MIT \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/$pkgname/LICENSE-MIT

  cd build-${MSYSTEM}/target/release/build

  # Package the man page
  find . -name bat.1 -type f -exec install -Dm644 {} \
    "${pkgdir}${MINGW_PREFIX}"/share/man/man1/bat.1 \;

  find . -name bat.zsh -type f -exec install -Dm644 {} \
    "${pkgdir}${MINGW_PREFIX}"/share/zsh/site-functions/_bat \;

  # Package the fish completion
  find . -name bat.fish -type f -exec install -Dm644 {} \
    "${pkgdir}${MINGW_PREFIX}"/share/fish/vendor_completions.d/bat.fish \;

}
